{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 安装Jupyter Notebook环境\n",
    "\n",
    "***************\n",
    "\n",
    "###  Jupyter Notebook介绍\n",
    "\n",
    "Jupyter项目是一个非盈利的开源项目，源于2014年的ipython项目，因为它逐渐发展为支持跨所有编程语言的交互式数据科学和科学计算\n",
    "\n",
    "* Jupyter Notebook，原名IPython Notbook，是IPython的加强网页版，一个开源Web应用程序\n",
    "\n",
    "* 名字源自Julia、Python 和 R（数据科学的三种开源语言）\n",
    "* 是一款程序员和科学工作者的**编程/文档/笔记/展示**软件\n",
    "* **.ipynb**文件格式是用于计算型叙述的**JSON文档格式**的正式规范\n",
    "\n",
    "![](./res/jupyternotebook.png)\n",
    "\n",
    "### 为什么使用Jupyter Notebook\n",
    "\n",
    "- 传统软件开发：\b工程／目标明确\n",
    "  - 需求分析，设计架构，开发模块，测试\n",
    "- 数据\b挖掘：艺术／目标不明确\n",
    "  - 目的是具体的洞察目标，而不是机械的完成任务\n",
    "  - 通过执行代码来理解问题\n",
    "  - 迭代式地改进代码来改进解决方法\n",
    "\n",
    "实时运行的代码、叙事性的文本和可视化被整合在一起，方便使用代码和数据来讲述故事。特别适合做笔记。并且可以上传到github/gitee上面 手机/平板/pc 方便观看\n",
    "\n",
    "\n",
    "\n",
    "**对比Jupyter Notebook和Pycharm**\n",
    "\n",
    "- 画图\n",
    "\n",
    "![img](./res/%E5%B1%95%E7%A4%BA1.png)\n",
    "\n",
    "* 数据展示\n",
    "\n",
    "![img](./res/%E5%B1%95%E7%A4%BA2.png)\n",
    "\n",
    "- 总结：Jupyter Notebook 相比 Pycharm 在画图和数据展示方面更有优势。\n",
    "\n",
    "## 安装Jupyter Notebook\n",
    "\n",
    "终端输入：pip3 install jupyter\n",
    "\n",
    "## jupyter 配置\n",
    "\n",
    "- 生成配置文件\n",
    "\n",
    "  - **jupyter notebook --generate-config**\n",
    "  \n",
    "    - **C:%HOMEPATH%/.jupyter/jupyter_notebook_config.py**\n",
    "\n",
    "    - 添加下面内容\n",
    "        - c.NotebookApp.ip = '*'\n",
    "        - c.NotebookApp.open_browser = False\n",
    "        - c.NotebookApp.port = 8888\n",
    "        - c.NotebookApp.notebook_dir = '你的code路径'\n",
    "\n",
    "- 生成访问密码\n",
    "    - **jupyter notebook password**\n",
    "\n",
    "- 运行jupyter\n",
    "    - **jupyter notebook**\n",
    "    - 然后通过浏览器打开 本地notebook的默认URL为：http://localhost:8888\n",
    "\n",
    "- linux不需要终端运行（高级操作）：\n",
    "    - **nohup jupyter notebook --allow-root > jupyter.log 2>&1 &**\n",
    "    \n",
    "**[jupter 开机自启（高级操作）](http://note.youdao.com/noteshare?id=f081dd73ceac024ff4229114cbb2ff5f&sub=80DA157AD53F428B9CD2FB65CC854D54)**\n",
    "\n",
    "## Jupyter Notebook的使用-helloworld\n",
    "\n",
    "### 界面启动、创建文件\n",
    "\n",
    "####  界面启动\n",
    "\n",
    "![notebook1](./res/notebook1.png)\n",
    "\n",
    "####  新建notebook文档\n",
    "\n",
    "- \bnotebook的文档格式是`.ipynb`\n",
    "\n",
    "![img](./res/createnotebook.png)\n",
    "\n",
    "#### 内容界面操作-helloworld\n",
    "\n",
    "**标题栏：**点击标题（如Untitled）修改文档名\n",
    "\n",
    "**编辑栏：**\n",
    "\n",
    "![controlnotebook](./res/jupyter_helloworld.png)\n",
    "\n",
    "### cell操作\n",
    "\n",
    "- 什么是cell？\n",
    "  - **cell**：一对In Out会话被视作一个代码单元，称为cell\n",
    "  - cell行号前的 * ，表示\b代码正在运行\n",
    "\n",
    "Jupyter支持两种模式：\n",
    "\n",
    "- 编辑模式（Enter）\n",
    "  - 命令模式下`回车Enter`或`鼠标双击`cell进入编辑模式\n",
    "  - 可以**操作cell内文本**或代码，剪切／复制／粘贴移动等操作\n",
    "- 命令模式（Esc）\n",
    "  - 按`Esc`退出编辑，进入命令模式\n",
    "  - 可以**操作cell单元本身**进行剪切／复制／粘贴／移动等操作\n",
    "\n",
    "#### 鼠标操作\n",
    "\n",
    "![工具栏cell](./res/%E5%B7%A5%E5%85%B7%E6%A0%8Fcell.png)\n",
    "\n",
    "#### 快捷键操作\n",
    "\n",
    "- 两种模式通用快捷键\n",
    "  - **`Shift+Enter`，执行本单元代码，并跳转到下一单元**\n",
    "  - **`Ctrl+Enter`，执行本单元代码，留在本单元**\n",
    "\n",
    "- **命令模式**：按ESC进入\n",
    "  - `Y`，cell切换到Code模式\n",
    "  - `M`，cell切换到Markdown模式\n",
    "  - `A`，在当前cell的上面添加cell\n",
    "  - `B`，在当前cell的下面添加cell\n",
    "\n",
    "- 其他(了解)\n",
    "  - `双击D`：删除当前cell\n",
    "  - `Z`，回退\n",
    "  - `L`，为当前cell加上行号 <!--\n",
    "  - `Ctrl+Shift+P`，对话框输入命令直接运行\n",
    "  - 快速跳转到首个cell，`Crtl+Home`\n",
    "  - 快速跳转到最后一个cell，`Crtl+End` -->\n",
    "\n",
    "- **编辑模式**：按Enter进入\n",
    "  - 补全代码：变量、方法后跟`Tab键`\n",
    "  - 为一行或多行代码添加/取消注释：`Ctrl+/`（Mac:CMD+/）\n",
    "\n",
    "- 其他(了解)：\n",
    "  - 多光标操作：`Ctrl键点击鼠标`（Mac:CMD+点击鼠标）\n",
    "  - 回退：`Ctrl+Z`（Mac:CMD+Z）\n",
    "  - 重做：`Ctrl+Y`（Mac:CMD+Y)\n",
    "\n",
    "### markdown演示\n",
    "\n",
    "掌握标题和缩进即可\n",
    "\n",
    "![img](./res/markdown%E6%BC%94%E7%A4%BA1.png)\n",
    "\n",
    "# 一级标题\n",
    "\n",
    "## 二级标题\n",
    "\n",
    "### 三级标题\n",
    "\n",
    "#### 四级标题\n",
    "\n",
    "##### 五级标题\n",
    "\n",
    "- 缩进\n",
    "  - 二级缩进\n",
    "    - 三级缩进\n",
    "\n",
    "## Jupyter Notebook中自动补全代码等相关功能拓展【了解】\n",
    "\n",
    "效果展示：\n",
    "\n",
    "![image-20190312225838970](./res/nbextnsions1.png)\n",
    "\n",
    "安装jupyter_contrib_nbextensions库\n",
    "\n",
    "安装该库的命令如下：\n",
    "\n",
    "```shell\n",
    "python -m pip install jupyter_contrib_nbextensions\n",
    "```\n",
    "\n",
    "然后执行：\n",
    "\n",
    "```shell\n",
    "jupyter contrib nbextension install --user --skip-running-check\n",
    "```\n",
    "\n",
    "在原来的基础上勾选： “Table of Contents” 以及 “Hinterland”\n",
    "\n",
    "部分功能：\n",
    "\n",
    "![image-20190313100409052](./res/nbextensions2.png)\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.0"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
